package cn.tedu.ps;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class PSProducer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //1.通过连接工厂对象配置连接信息
        ConnectionFactory cf = new ConnectionFactory();
        cf.setHost("172.26.6.53");//写成自己的ip
        cf.setPort(5672); //5672是客户端端口，15672是UI界面端口，25672是erlang发现口
        cf.setUsername("guest");
        cf.setPassword("guest");
        //2.创建tcp和channel
        Connection nc = cf.newConnection();
        Channel cc = nc.createChannel();
        //3.创建一个fanout类型的交换机
        cc.exchangeDeclare("fanout_exchange", BuiltinExchangeType.FANOUT);
        //4.向交换机发送数据
        while (true){
            System.out.print("输入消息:");
            String message = new Scanner(System.in).nextLine();
            if (message.equals("quit"))
                break;
            cc.basicPublish("fanout_exchange","", null,message.getBytes());
        }
        nc.close();
    }
}
